<?php
        date_default_timezone_set('America/Bogota');
  	$DB_Server = "localhost";        //your MySQL Server 
	$DB_Username = "root";                 //your MySQL User Name 
	$DB_Password = "123456";                //your MySQL Password
	$DB_DBName = "examenes";                //your MySQL Database Name
        $hora =date('H');


	//create MySQL connection
	$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
	or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno());
	//select database
	$Db = @mysql_select_db($DB_DBName, $Connect)
	or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno());

        $cod_est  = $_REQUEST['cod_est']; //codigo del estudiante
        //Consulta para extraer los parcial que tiene el estudiante el dia de hoy (curdate())
        $sql = "SELECT * FROM estudiante est
                inner join asigna asi on asi.cod_est = est.cod_est
                inner join parcial par on par.cod_par = asi.cod_par
                where est.cod_est = $cod_est and fec_par = curdate()";
	$result = @mysql_query($sql,$Connect)
	or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno());
        $row = mysql_fetch_array($result);
        //Verifica que exista un resultado
        if(is_array($row)){
            echo "<table border = 1>";
            echo "<tr>";
            echo "<th>Nombre</th>";
            echo "<th>Fecha Parcial</th>";
            echo "<th>Hora</th>";
            echo "<th>Duracion</th>";
            echo "<th>Hora Actual</th>";
            echo "<th>Estado</th>";
            echo "</tr>";
            //Para cada uno de los parciales que tiene hoy
            do {
                echo "<tr>";
                echo "<td>{$row['nom_est']}</td>";
                echo "<td>{$row['fec_par']}</td>";
                echo "<td>{$row['hor_par']}</td>";
                echo "<td>{$row['dur_par']}</td>";
                echo "<td>$hora</td>";
                if($hora > ($row['hor_par'] + $row['dur_par']))
                    echo "<td>Cerrado</td>";
                else
                    echo "<td>Abierto</td>";
                echo "</tr>";
            }while($row=mysql_fetch_array($result));
            echo "</table>";
        }
        else
            echo "<h2>No tiene parciales programados para el dia de hoy</h2>";

?>